package com.example.serviceopenactivity

import android.app.Service
import android.content.Intent
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import android.util.Log

class LocalService : Service() {
    var handler: Handler? = null
    override fun onBind(p0: Intent?): IBinder? {
        return null
    }

    override fun onCreate() {
        Log.i("LocalService", "onCreate - Thread ID = " + Thread.currentThread().getId())
        handler = Handler(Looper.getMainLooper())
        super.onCreate()
        handler?.postDelayed({
            var intent = Intent("activity2")
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            startActivity(intent)
        }, 2555)

    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        Log.i(
            "LocalService",
            "onStartCommand - startId = " + startId + ", Thread ID = " + Thread.currentThread().getId()
        )
        return super.onStartCommand(intent, flags, startId)
    }
}